package org.global.basic.specification;

import org.global.GEntity;
import org.springframework.data.jpa.domain.Specification;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.io.Serializable;
import java.util.Map;

public class SpecNotDel {

    static class SpecNotDelImpl<T extends GEntity<ID>, ID extends Serializable> implements Specification<T> {
        @Override
        public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
            return criteriaBuilder.equal(root.get("del").as(Boolean.class), false);
        }
    }

    static class NotDelFactory implements ConditionUnitFactory {

        @Override
        public <ID extends Serializable, T extends GEntity<ID>> Specification<T> createSpec(Map<String, Object> param) {
            return new SpecNotDelImpl<>();
        }
    }

}
